package midware

import (
	"github.com/cihub/seelog"
	"github.com/gin-gonic/gin"
	"runtime/debug"
	"shop/utils/result"
)

// Recover 自定义panic异常处理
func Recover(c *gin.Context) {
	// seelog.Debugf("path: %s, headers: %v", c.FullPath(), c.Request.Header)
	defer func() {
		if err := recover(); err != nil {
			seelog.Errorf("panic err:%v", err)
			debug.PrintStack()
			result.RenderResult(c, result.Fail("server inner error(panic recover)"))
			c.Abort()
		}
	}()
	c.Next()
}
